#include <stdio.h>
#include <stdlib.h>


//设定一个结构体A，存放队列的头尾指针
//定义一个单向链表B，存放数据
//A的头指针指向B的头，头插时直接对B操作
//A的尾指针指向B的尾，尾删时直接对B操作
//进行添加或删除操作时，直接拿A的名称进行操作
typedef struct dblink {
    int data;
    struct dblink *from;
    struct dblink *next;
} dblink_t;

typedef struct linkqueue {
    struct dblink *head;
    struct dblink *tail;
} linkqueue_t;

linkqueue_t *create_linkqueue() 
{
    linkqueue_t *q;
    dblink_t *dl;
    q = malloc(sizeof(linkqueue_t));
    dl = malloc(sizeof(dblink_t));
    dl->from = NULL;
    dl->next = NULL;
    q->head = dl;
    q->tail = dl;
    return q;
}

int in_linkqueue(struct linkqueue *lq, int *d) 
{
    dblink_t *dl;
    dl = malloc(sizeof(dblink_t));
    dl->data = *d;
    dl->from = lq->head;
    dl->next = lq->head->next;
    lq->head->next = dl;
    if(lq->head == lq->tail) {
        lq->tail = dl;
    }
    return 0;
}

int out_linkqueue(struct linkqueue *lq) 
{
    dblink_t *dl;
    //如果头尾相等，则无数据
    if(lq->head == lq->tail) {
        return -1;
    } else {
        dl = lq->tail->from;
        lq->tail->from->next = NULL;
        lq->tail = lq->tail->from;
        return 0;
    }
}

int get_head_linkqueue(struct linkqueue *lq)
{
    return lq->head->next->data;
}

int is_empty_linkqueue()
{

}

int is_full_linkqueue()
{
}

int main( int argc, const char *argv[]) 
{
    linkqueue_t *lq;
    int *d;
    *d = 10;
    lq = create_linkqueue();

    //in_linkqueue(lq, d);
    //printf("出队:%d\n", out_linkqueue(lq));
}

